package ysq.xyg.web.controller;

import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.web.model.po.WebAppMenu;
import ysq.xyg.web.model.vo.WebAppMenuVo;
import ysq.xyg.web.service.WebAppMenuService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 业务模块-APP菜单-业务模块-APP菜单controller层
 *
 * @author congcong tao
 * @date 2019-10-29 10:20:29
 */
@RestController
public class WebAppMenuController extends BaseController {

    @Resource
    private WebAppMenuService webAppMenuService;

    /**
     * 分页查询
     *
     * @param webAppMenuVo 对象
     * @param pageSize     展示数量
     * @param pageNum      当前页面
     * @author congcong tao
     * @date 2019-10-29 10:20:29
     */
    @BaseLog(module = "业务模块-APP菜单", className = "业务模块-APP菜单", methods = "分页查询", businessType = BaseConstant.SYS_BUSINESS_TYPE_GET, operatorType = BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAppMenu/page", method = RequestMethod.POST)
    public ReturnEntity page(HttpServletRequest request, WebAppMenuVo webAppMenuVo, int pageSize, int pageNum) {
        webAppMenuVo.setAccountId(acceptAccountId(request));
        ReturnEntity returnEntity = webAppMenuService.page(webAppMenuVo, pageSize, pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-10-29 10:20:29
     */
    @RequestMapping(value = "/webAppMenu/getEntity", method = RequestMethod.GET)
    public ModelAndView getEntity(String id) {
        ModelAndView view = new ModelAndView("/web/webAppMenuUpdateOrSave");
        if (StrUtil.isNotEmpty(id)) {
            WebAppMenu webAppMenu = webAppMenuService.selectByPrimaryKey(id);
            view.addObject("webAppMenu", webAppMenu);
        }
        return view;
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-10-29 10:20:29
     */
    @BaseLog(module = "业务模块-APP菜单", className = "业务模块-APP菜单", methods = "删除", businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE, operatorType = BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAppMenu/delete")
    public ReturnEntity delete(HttpServletRequest request, String id) {
        return webAppMenuService.delete(id, acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webAppMenuVo Vo对象
     * @author congcong tao
     * @date 2019-10-29 10:20:29
     */
    @BaseLog(module = "业务模块-APP菜单", className = "业务模块-APP菜单", methods = "添加或修改", businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE, operatorType = BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAppMenu/addOrUpdate", method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request, WebAppMenuVo webAppMenuVo) {
        return webAppMenuService.addOrUpdate(webAppMenuVo, acceptCurrentUser(request));
    }
}